#include "leddialog.h"
#include "ui_leddialog.h"
#include "lib/qthttp.h"
#include <QtNetwork/QNetworkAccessManager>
#include <QtNetwork/QNetworkReply>
#include <unistd.h>

LedDialog::LedDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::LedDialog)
{
    ui->setupUi(this);
}

LedDialog::~LedDialog()
{
    delete ui;
}

void LedDialog::httpFinished_1(){

    QByteArray ret;

    ret = reply->readAll();

    ui->label_led1->setText(QString(ret));
}

int LedDialog::webget(const char* url,char* result){
    QByteArray rst;
    QNetworkRequest request;
    request.setUrl(QUrl(url));

    manager = new QNetworkAccessManager(this);
    reply = manager->get(request);
    connect(reply,SIGNAL(finished()),this,SLOT(httpFinished_1()));

    return 0;
    /*usleep(100000);

    rst = reply->readAll();

    if(rst.size()<0)
        return -1;
    else
        result = rst.data();*/
    //return reply->readAll();
    //connect(_networkManager,SIGNAL(finished(QNetworkReply*)),this,SLOT(replyFinished(QNetworkReply*)));

}
#if 0
void LedDialog::on_pushButton_o1_clicked()
{
    const char* url = "http://192.168.0.232/android_7inch/cgi-bin/relay_control.cgi?relayNo=1&relayStatus=0";
    char result[100];

    memset(result,0,sizeof(result));
    webget(url,result);
/*
    if(strlen(result)==0){
        ui->label_led1->setText(QString("No Result"));
    }else{
        ui->label_led1->setText(QString(result));
    }*/
//}
#endif
void LedDialog::on_pushButton_led1on_clicked()
{
    ui->label_led1->setStyleSheet(QString("background-image: url(:/new/prefix1/ledon.png);"));
}

void LedDialog::on_pushButton_led1off_clicked()
{
    ui->label_led1->setStyleSheet(QString("background-image: url(:/new/prefix1/ledoff.png);"));
}

void LedDialog::on_pushButton_led2on_clicked()
{
    ui->label_led2->setStyleSheet(QString("background-image: url(:/new/prefix1/ledon.png);"));
}

void LedDialog::on_pushButton_led2off_clicked()
{
    ui->label_led2->setStyleSheet(QString("background-image: url(:/new/prefix1/ledoff.png);"));
}

void LedDialog::on_pushButton_led3on_clicked()
{
    ui->label_led3->setStyleSheet(QString("background-image: url(:/new/prefix1/ledon.png);"));
}

void LedDialog::on_pushButton_led3off_clicked()
{
    ui->label_led3->setStyleSheet(QString("background-image: url(:/new/prefix1/ledoff.png);"));
}

void LedDialog::on_pushButton_led4on_clicked()
{
    ui->label_led4->setStyleSheet(QString("background-image: url(:/new/prefix1/ledon.png);"));
}

void LedDialog::on_pushButton_led4off_clicked()
{
    ui->label_led4->setStyleSheet(QString("background-image: url(:/new/prefix1/ledoff.png);"));
}
